clear all;close all;clc

info = audiodevinfo
info.input.Name
% IO=1 % 0 output; 1 input
% nDevices = audiodevinfo(IO)
% name = audiodevinfo(IO,ID)
% DriverVersion = audiodevinfo(IO,ID,"DriverVersion")
% support = audiodevinfo(IO,ID,Fs,nBits,nChannels)
% devID = audiodevinfo(IO,devName)
% suppDevID = audiodevinfo(IO,Fs,nBits,nChannels)

[Y Fs]=audioread('romantic-story-130375.mp3');
% Fs = 44.1e3;

dt=1/Fs;
dur = 5;
Y = Y(round(dur*Fs)+1:2*round(dur*Fs),1);
tsig = dt:dt:dur;

BBnoise = Y;
SPL = 60;
rms_want = 10.^(SPL/20).*20e-6;
BBnoise = BBnoise./rms(BBnoise).*rms_want;
sound(BBnoise,Fs)

input_ID = 1
N_channel=2;
recObj = audiorecorder(Fs,16,N_channel,input_ID);
disp("Begin recording.")
recordblocking(recObj,dur);
disp("End of recording.")
y = getaudiodata(recObj);
figure;plot(y)
